'use strict';
const db = uniCloud.database();
const newsCollection = db.collection('newsCollection');

exports.main = async (event, context) => {
  try {
    const res = await newsCollection.get();
    return {
      code: 200,
      data: res.data,
      message: "获取新闻成功"
    };
  } catch (error) {
    console.error("获取新闻失败：", error);
    return {
      code: 500,
      message: "获取新闻失败"
    };
  }
};